//
//  AppDelegate.m
//  Project_A Gary
//
//  Created by leilei on 16/3/23.
//  Copyright © 2016年 www.lei.com. All rights reserved.
//

#import "AppDelegate.h"
#import "InformationViewController.h"
#import "ForumViewController.h"
#import "FindViewController.h"
#import "PreferentialLeftViewController.h"

#import "MineViewController.h"

#import "RESideMenu.h"
#import "MineViewController.h"
#import "MenuViewController.h"


// 签订一个menu的协议
@interface AppDelegate ()<RESideMenuDelegate>

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    
    // 设置tabBar
    // 页面1. 资讯页面
    InformationViewController *informationVC = [[InformationViewController alloc] init];
    UINavigationController *informationNAVI = [[UINavigationController alloc] initWithRootViewController:informationVC];
    informationNAVI.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"资讯" image:[UIImage imageNamed:@"information.png"] tag:1000];
    
    
    // 页面2. 论坛页面
    ForumViewController *forumVC = [[ForumViewController alloc] init];
    UINavigationController *forumNAVI = [[UINavigationController alloc] initWithRootViewController:forumVC];
    forumNAVI.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"论坛" image:[UIImage imageNamed:@"forum.png"] tag:1001];
    
    
    // 页面3. 找车页面
    FindViewController *findVC = [[FindViewController alloc] init];
    UINavigationController *findNAVI = [[UINavigationController alloc] initWithRootViewController:findVC];
    findNAVI.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"找车" image:[UIImage imageNamed:@"find.png"] tag:1002];
    
    // 页面4. 优惠页面
    PreferentialLeftViewController *preferentialVC = [[PreferentialLeftViewController alloc] init];
    UINavigationController *preferentialNAVI = [[UINavigationController alloc] initWithRootViewController:preferentialVC];
    preferentialNAVI.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"优惠" image:[UIImage imageNamed:@"preferential.png"] tag:1003];
    
    //  页面5. 我的页面
    MineViewController *mineVC = [[MineViewController alloc] init];
    UINavigationController *mineNAVI = [[UINavigationController alloc] initWithRootViewController:mineVC];
    mineNAVI.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我的" image:[UIImage imageNamed:@"mine.png"] tag:1004];
    
    
    
    
    //设置tabBar
    UITabBarController *tabBar = [[UITabBarController alloc] init];
    tabBar.viewControllers = @[informationNAVI, forumNAVI, findNAVI, preferentialNAVI, mineNAVI];
    //tabBar.tabBar.barTintColor = [UIColor whiteColor];
    
    // 将根视图设置为tabBar
//    self.window.rootViewController = tabBar;
    
    
    
    
    
#pragma mark - "我的"页面抽屉效果创建对象
    
    // 建立一个抽屉VC的对象
    MenuViewController *menuVC = [[MenuViewController alloc] init];
    
    
    // 建立一个抽屉菜单(切换VC 与 VC)
    RESideMenu *reMenu = [[RESideMenu alloc] initWithContentViewController:tabBar leftMenuViewController:nil rightMenuViewController:menuVC];
    reMenu.delegate = self;
    reMenu.contentViewShadowColor = [UIColor blackColor];
    reMenu.contentViewShadowOffset = CGSizeMake(0, 0);
    reMenu.contentViewShadowOpacity = 0.6;
    reMenu.contentViewShadowRadius = 12;
    reMenu.contentViewShadowEnabled = YES;
    reMenu.scaleContentView = NO;
    reMenu.scaleMenuView = NO;
    reMenu.scaleBackgroundImageView = NO;
    
    self.window.rootViewController = reMenu;
    
    
    
    // 释放
    [informationVC release];
    [informationNAVI release];
    [forumVC release];
    [forumNAVI release];
    [findVC release];
    [findNAVI release];
    [preferentialVC release];
    [preferentialNAVI release];
    [mineVC release];
    [mineNAVI release];
    
    [tabBar release];
    
    

    
    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
